package com.bric.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPools {
	private static ThreadPools theadPools=null;
	private static ThreadPoolExecutor exexutorPool;
	public ThreadPoolExecutor getTheadPools(){
		if(null==exexutorPool){
			synchronized (ThreadPools.class) {
				if(null==exexutorPool){
					ThreadFactory threadFactory=Executors.defaultThreadFactory();
					exexutorPool=new ThreadPoolExecutor(8,
							8, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(2), 
							threadFactory, new RejectHander());
				}
			}
		}
		return exexutorPool;
		
	}
	private ThreadPools() {
		// TODO Auto-generated constructor stub
	}
	public static ThreadPools getSingleton(){
		if(null==theadPools){
			synchronized (ThreadPools.class) {
				if(null==theadPools){
					theadPools=new ThreadPools();
				}
			}
		}
		return theadPools;
	}
	public static void main(String[] args) {
		ThreadPools.getSingleton().getTheadPools();
	}
}
